package com.doge.walknovel.core

import android.content.pm.ActivityInfo
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.doge.walknovel.analysis.analysisOnPageEnd
import com.doge.walknovel.analysis.analysisOnPageStart
import com.doge.walknovel.utils.Activities
import com.doge.walknovel.utils.closeKeyBoard
import com.doge.walknovel.utils.useTranslucentStatusBar
import com.doge.walknovel.widgets.imagecropper.ImageCropperHelper

open class BaseActivity : AppCompatActivity() {
    open val statusBarLightMode: Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        useTranslucentStatusBar(statusBarLightMode)

        Activities.add(this)
    }

    override fun onResume() {
        super.onResume()
        analysisOnPageStart()
    }

    override fun onPause() {
        super.onPause()
        analysisOnPageEnd()
    }

    override fun onDestroy() {
        super.onDestroy()
        Activities.remove(this)

    }

    override fun finish() {
        super.finish()
        closeKeyBoard()
    }

    override fun onBackPressed() {
        if (ImageCropperHelper.tryCloseCropper()) return // 全局应用拦截裁剪view的back返回事件
        super.onBackPressed()
    }
}